home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / states / SetProperty.as < prev    next >
Text File  |  2014-03-27  |  4KB  |  127 lines

  1. package mx.states
  2. {
  3.    import mx.core.UIComponent;
  4.    import mx.core.mx_internal;
  5.    
  6.    use namespace mx_internal;
  7.    
  8.    public class SetProperty implements IOverride
  9.    {
  10.       
  11.       private static const RELATED_PROPERTIES:Object = {
  12.          "explicitWidth":["percentWidth"],
  13.          "explicitHeight":["percentHeight"]
  14.       };
  15.       
  16.       mx_internal static const VERSION:String = "3.0.0.0";
  17.       
  18.       private static const PSEUDONYMS:Object = {
  19.          "width":"explicitWidth",
  20.          "height":"explicitHeight"
  21.       };
  22.        
  23.       
  24.       private var oldRelatedValues:Array;
  25.       
  26.       private var oldValue:Object;
  27.       
  28.       public var name:String;
  29.       
  30.       public var target:Object;
  31.       
  32.       public var value;
  33.       
  34.       public function SetProperty(param1:Object = null, param2:String = null, param3:* = undefined)
  35.       {
  36.          super();
  37.          this.target = param1;
  38.          this.name = param2;
  39.          this.value = param3;
  40.       }
  41.       
  42.       public function remove(param1:UIComponent) : void
  43.       {
  44.          var _loc5_:int = 0;
  45.          var _loc2_:Object = !!target ? target : param1;
  46.          var _loc3_:String = !!PSEUDONYMS[name] ? PSEUDONYMS[name] : name;
  47.          var _loc4_:Array = !!RELATED_PROPERTIES[_loc3_] ? RELATED_PROPERTIES[_loc3_] : null;
  48.          if((name == "width" || name == "height") && !isNaN(Number(oldValue)))
  49.          {
  50.             _loc3_ = name;
  51.          }
  52.          setPropertyValue(_loc2_,_loc3_,oldValue,oldValue);
  53.          if(_loc4_)
  54.          {
  55.             _loc5_ = 0;
  56.             while(_loc5_ < _loc4_.length)
  57.             {
  58.                setPropertyValue(_loc2_,_loc4_[_loc5_],oldRelatedValues[_loc5_],oldRelatedValues[_loc5_]);
  59.                _loc5_++;
  60.             }
  61.          }
  62.       }
  63.       
  64.       private function toBoolean(param1:Object) : Boolean
  65.       {
  66.          if(param1 is String)
  67.          {
  68.             return param1.toLowerCase() == "true";
  69.          }
  70.          return param1 != false;
  71.       }
  72.       
  73.       public function apply(param1:UIComponent) : void
  74.       {
  75.          var _loc6_:int = 0;
  76.          var _loc2_:Object = !!target ? target : param1;
  77.          var _loc3_:String = !!PSEUDONYMS[name] ? PSEUDONYMS[name] : name;
  78.          var _loc4_:Array = !!RELATED_PROPERTIES[_loc3_] ? RELATED_PROPERTIES[_loc3_] : null;
  79.          var _loc5_:* = value;
  80.          oldValue = _loc2_[_loc3_];
  81.          if(_loc4_)
  82.          {
  83.             oldRelatedValues = [];
  84.             _loc6_ = 0;
  85.             while(_loc6_ < _loc4_.length)
  86.             {
  87.                oldRelatedValues[_loc6_] = _loc2_[_loc4_[_loc6_]];
  88.                _loc6_++;
  89.             }
  90.          }
  91.          if(name == "width" || name == "height")
  92.          {
  93.             if(_loc5_ is String && _loc5_.indexOf("%") >= 0)
  94.             {
  95.                _loc3_ = name == "width" ? "percentWidth" : "percentHeight";
  96.                _loc5_ = _loc5_.slice(0,_loc5_.indexOf("%"));
  97.             }
  98.             else
  99.             {
  100.                _loc3_ = name;
  101.             }
  102.          }
  103.          setPropertyValue(_loc2_,_loc3_,_loc5_,oldValue);
  104.       }
  105.       
  106.       public function initialize() : void
  107.       {
  108.       }
  109.       
  110.       private function setPropertyValue(param1:Object, param2:String, param3:*, param4:Object) : void
  111.       {
  112.          if(param4 is Number)
  113.          {
  114.             param1[param2] = Number(param3);
  115.          }
  116.          else if(param4 is Boolean)
  117.          {
  118.             param1[param2] = toBoolean(param3);
  119.          }
  120.          else
  121.          {
  122.             param1[param2] = param3;
  123.          }
  124.       }
  125.    }
  126. }
  127.